Page({
  data: {
    text: '长按签到',
    firstTime: '0',
    flag: true,
    animation: '',
    // 保存签到时间
    timeList:[]
    
  },
  // 长按事件 动画+签到
  animationEvent(e) {
    var T = new Date();
    var Y = T.getFullYear();
    var M = T.getMonth()+1;
    var D = T.getDate();
    var H = T.getHours();
    var MT = T.getMinutes();
    var S = T.getSeconds();
    let temp = [];
    temp.push(Y);
    temp.push(M);
    temp.push(D);
    temp.push(H);
    temp.push(MT);
    temp.push(S);
    // console.log(T,Y)


    var animation = wx.createAnimation({
      duration: 2000,
      timingFunction: 'linear',
    });
// 旋转一周
    animation.rotate(360).step();
    var D = (new Date()).getDate().toString();
    // console.log("wx.getStorageSyncOnBindTap1133311=" + wx.getStorageSync('D'))
    var DT = wx.getStorageSync('D');

    // var D = (new Date()).getDate().toString();
    // if (parseInt(D) != parseInt(DT) + 1) {
    //   //非连续签到 对应的操作
    // } else {
    //   //连续签到
    // }

    if (D != wx.getStorageSync('D')) {
      wx.setStorageSync('D', D);
      wx.setStorage({
        key: 'FirstTime',
        data: (parseInt(this.data.firstTime) + 1).toString(),
      })
      var that = this;
      var firstTime = wx.getStorage({
        key: 'FirstTime',
        success: function(res) {
      
            that.setData({
              firstTime: res.data,
              flag: false,
              animation: animation.export(),
              text: '今日打卡已完成！',
              timeList:temp
            })

          wx.setStorage({
            key: 'timeList',
            data: that.data.timeList,
          })
         
          // wx.showToast({
          //   title: '签到成功！',
          //   icon: 'success',
          //   duration: 1200,
          //   mask: true
          // })
    
        },
      })
    } else {
      
      var animation = wx.createAnimation({
        duration: 2000,
        timingFunction: 'linear',
      });

      animation.rotate(-360).step();
      this.setData({
        animation: animation.export(),
      })
    
      // wx.showToast({
      //   title: '今日打卡已完成！',
      //   icon: 'loading',
      //   duration: 1200,
      //   mask: true
      // })
    }


  },
  // 清除key
  clearKey: function() {
    wx.removeStorage({
      key: 'D',
      key: 'FirstTime',
      success(res) {
        console.log(wx.getStorageSync('D'))
        console.log(wx.getStorageSync('FirstTime'))
      }
    })
    try {
      wx.removeStorageSync('D')
    } catch (e) {
      console.log(e)
    }
  },

  onBindTap: function() {

  },
  onShow: function(options) {

    var that = this;
    console.log(that)
    // 获取key
    var firstTime = wx.getStorage({
      key: 'FirstTime',
      success: function(res) {
        console.log("succes")
        that.setData({
          firstTime: res.data

        })
      },
    })
    var D = (new Date()).getDate().toString();
    console.log("wx.getStorageSync=" + wx.getStorageSync('D'))
    if (D != wx.getStorageSync('D')) {
      console.log("ddddddddddddddd")
      this.setData({
        flag: true
      })
    } else {

      this.setData({
        flag: false
      })
    }
  },


})